package com.zgroup.domain

import com.zgroup.domain.SysUser

class EstatePicture implements Comparable {
    
    final static String UPLOAD_THUMBNAIL_PATH = "/images/estate_picture/"
    final static String UPLOAD_FILE_PATH = "/images/estate_picture/"
    final static String EPIC_TYPE_COMMUNITY = "10"  //小区
    final static String EPIC_TYPE_HOUSE = "20"       //房型
    final static String EPIC_TYPE_ROOM = "30"  //室内

    String fileName
    String picType
    Estate estate
    String title
    String summary
    String showFlag = '1'  // 显示标记位 1：显示 0：不显示
    String approveFlag = '1'  // 审批通过标记 0:审核中 1：通过  2:不通过
    Date dateCreated
    User publisher
    SysUser approveUser
    
    static transients = ['fileFullName', 'thumbFullName','picTypePath']

    int compareTo(obj) {
        dateCreated.compareTo(obj.dateCreated)
    }

    static constraints = {
        fileName(blank: false,maxSize: 50)
        picType(blank: false,maxSize: 6)
        estate(nullable: true)
        title(nullable: true,maxSize: 50)
        summary(nullable: true,maxSize: 255)
        approveFlag(blank: false,maxSize: 6)
        showFlag(blank: false,maxSize: 6)
    }

    static mapping = {
        cache true
        dynamicInsert true
        dynamicUpdate true
    }

    String getPicTypePath(){
        if(picType==EPIC_TYPE_HOUSE){
            return "a"
        }else if(picType==EPIC_TYPE_COMMUNITY){
            return "b"
        }
        return "c"
    }
    String getFileFullName() {
        return UPLOAD_FILE_PATH + estate.id + "/" + picTypePath +"/"+ fileName
    }

    String getThumbFullName() {
        return UPLOAD_THUMBNAIL_PATH + estate.id + "/" + picTypePath +"/"+ fileName
    }

    String toString() {
        "id:" + id
    }
}